// 获取英文日期格式
export function getUTCDate(date = new Date()) {
  console.log(date)
  // var date = new Date();
  var monthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August",
    "September", "October", "November", "December");
  var weekArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
  var month = date.getMonth();
  var day = date.getDate();
  if (day.toString().length == 1) {
    day = "0" + day.toString();
  }
  return {
    month: monthArray[month],
    day,
    year: date.getFullYear(),
    week: weekArray[date.getDay()]
  }
}
export function getNowFormatDate() {
  var date = new Date();
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  let formateHour = date.getHours()
  let state = ''
  if (formateHour >= 0 && formateHour <= 10) {
    state = `早上好`;
  } else if (formateHour > 10 && formateHour <= 14) {
    state = `中午好`;
  } else if (formateHour > 14 && formateHour <= 18) {
    state = `下午好`;
  } else if (formateHour > 18 && formateHour <= 24) {
    state = `晚上好`;
  }
  var hour= addZero(formateHour);//得到小时数
  var minute= addZero(date.getMinutes());//得到分钟数
  var second= date.getSeconds();//得到秒数
  // 获取今天是周几，0表示周日，1表示周一，以此类推直到6表示周六
  var dayOfWeek = date.getDay();
  // 创建一个数组，存储一周七天的名称
  var daysOfWeek = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
  return {
    year,
    month,
    strDate,
    hour,
    minute,
    second,
    state,
    week: daysOfWeek[dayOfWeek]
  };
}
function addZero (num) {
  if (parseInt(num) < 10) {
    num = '0' + num
  }
  return num
}
export function deepClone(source) {
  if (!source && typeof source !== "object") {
    throw new Error("error arguments", "deepClone");
  }
  const targetObj = source.constructor === Array ? [] : {};
  Object.keys(source).forEach(keys => {
    if (source[keys] && typeof source[keys] === "object") {
      targetObj[keys] = deepClone(source[keys]);
    } else {
      targetObj[keys] = source[keys];
    }
  })
  return targetObj;
}
export function debounce(fn, time = 300) {
  let timer
  return function () {
    var _that = this
    var arg = arguments
    // 高频率事件会在某个时间段内清除定时器，保证只执行最后一个
    if (timer) clearTimeout(timer)
    timer = setTimeout(() => {
      fn.call(_that, ...arg)
    }, time)
  }
}


export function formateDate() {
  var date = new Date();
  var month = date.getMonth();
  var year = date.getFullYear();
  var week = date.getDay();
  var month = month + 1;
  var day = date.getDate();
  // week：周几，day：几号
  var weekArr = [{ week: '', day: '' }, { week: '', day: '' }, { week: '', day: '' }, { week: '', day: '' }, { week: '', day: '' }, { week: '', day: '' }, { week: '', day: '' }];
  // 本周内今天的前几天的数量
  var leftNum = week;
  // 本周内今天的后几天的数量
  var rightNum = 7 - week;
  // 本周内今天的前几天
  for (var i = 0; i < leftNum; i++) {
    weekArr[i].week = week - (week - i) + 1;
    if (i == 0) {
      console.log(day, week)
      weekArr[i].day = day - week + 1;
    } else {
      weekArr[i].day = day - (week - i) + 1;
    }
  }
  // 本周内今天的后几天
  for (var i = 0; i < rightNum; i++) {
    weekArr[i + week].week = week + i + 1;
    weekArr[i + week].day = day + i + 1;
  }
  return {
    month: month < 10 ? '0' + month : month,
    day: day < 10 ? '0' + day : day,
    week: `${month < 10 ? '0' + month : month}月${weekArr[0].day}日-${month < 10 ? '0' + month : month}月${weekArr[weekArr.length - 1].day}日`,
    year
  }
  // 今天
  // weekArr[week-1].week = week;
  // weekArr[week-1].day = day;

}

// 判断时间为今天
export function getDistanceSpecifiedTime(dateTime) {
  // 指定日期和时间
  var EndTime = new Date(dateTime);
  // 当前系统时间
  var NowTime = new Date();
  var t = EndTime.getTime() - NowTime.getTime();
  var d = Math.floor(t / 1000 / 60 / 60 / 24);
  // var h = Math.floor(t / 1000 / 60 / 60 % 24);
  // var m = Math.floor(t / 1000 / 60 % 60);
  // var s = Math.floor(t / 1000 % 60);
  // var html = d + " 天" + h + " 时" + m + " 分" + s + " 秒";
  console.log(Math.abs(d), 'ssss');
  return Math.abs(d)
}
